package com.cls.business.strategy.impl.notice;

import com.cls.business.entity.DeclareTopic;
import com.cls.business.entity.Notice;
import com.cls.business.entity.Standard;
import com.cls.business.entity.TopicPlan;
import com.cls.business.service.*;
import com.cls.business.strategy.NoticeStrategy;
import com.cls.common.enums.DictEnum;
import com.cls.common.enums.MessageEnum;
import com.cls.common.exception.MyException;
import com.cls.system.entity.User;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 立项的实现方法
 *
 * @author Administrator
 */
@Component("notice_type_lxgg")
@RequiredArgsConstructor
public class LXGGNoticeImpl implements NoticeStrategy {

    private final INoticeService noticeService;
    private final ITopicPlanService topicPlanService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createNotice(Notice notice) {
        noticeService.save(notice);
        //拟立项公告发出之后，把所有的已评审状态的年度课题改成拟立项失败
        String year = notice.getYear();
        //根据年份查询年度课题
        TopicPlan topicPlan = topicPlanService.selectAnnualByYear(year);
        if (topicPlan == null) {
            throw new MyException("当前立项计划不存在！");
        }

        if (topicPlan.getItemNoticeId() != null) {
            throw new MyException("当前计划已被立项！");
        }
        topicPlan.setItemNoticeId(notice.getNoticeId());
        topicPlanService.updateById(topicPlan);
    }
}
